package qdu.rg05.test_music_srv;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;

public class Srv_1 extends Service {
    MediaPlayer mp;
    @Override
    public void onCreate() {
        super.onCreate();
        Log.i("mytag", "Srv_1  oncreate....");
        mp = MediaPlayer.create(this,R.raw.main);//创建媒体对象（媒体对应的当前上下文，媒体数据资源访问）
        mp.setLooping(true);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i("mytag", "Srv_1  onstartcommand....");
        if(mp!=null)
            if(mp.isPlaying())
                mp.pause();
            else
                mp.start();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("mytag", "Srv_1  ondestroy....");
        if(mp!=null) {
            mp.stop(); mp.release();
        }
    }

    //*****************************************
    @Override
    public IBinder onBind(Intent intent) {
        Log.i("mytag", "Srv_1  onbind....");
        return null;
    }
}
